<template>
	<view>
		<input type="text" @focus="toSearch">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="banner">
			<swiper-item v-for="(v, i) in swiperData" :key="i">
				<view class="swiper-item">
					<image :src="v" mode=""></image>
				</view>
			</swiper-item>
		</swiper>
		<div class="list">
			<navigator :url="'/pages/detail/detail?id=' + v.id" v-for="(v, i) in listData" :key="i">
				<list-item :item="v"></list-item>
			</navigator>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperData: [],
				listData: [],
			};
		},
		methods: {
			async getData() {
				const respSwiper = await uni.request({
					url: 'http://localhost:3000/banners'
				})
				
				const respList = await uni.request({
					url: 'http://localhost:3000/list'
				})
			
				
				this.swiperData = respSwiper.data
				this.listData = respList.data
			},
			toDetail(id) {
				console.log(123)
				uni.navigateTo({
					url: '/pages/detail/detail?id=' + id
				})
			},
			toSearch() {
				uni.navigateTo({
					url: '/pages/search/search'
				})
			}
		},
		onLoad() {
			this.getData()
		}
	}
</script>

<style lang="scss">
	.banner {
		height: 400rpx;

		.swiper-item {
			image {
				width: 100vw;
				height: 400rpx;
			}
		}
	}
	.list {
		display: flex;
		flex-wrap: wrap;
	}
</style>